package com.explorati.interview.interview.chapterfour;

import java.util.HashSet;

public class Dog {

	private String name;
	private int age;
	private static HashSet<Dog> pool = new HashSet<Dog>();

	public Dog(String name, int age) {
		this.name = name;
		this.age = age;
	}

	public static Dog newInstance(String name, int age){
		for(Dog dog : pool){
			if(dog.name.equals(name) && dog.age == age){
				return dog;
			}
		}
		Dog dog = new Dog(name, age);
		pool.add(dog);
		return dog;
	}
}

